export default class PageState {
    constructor(page) {
        this.page = page;
        this.stateH = {};
        this.useDoSetStateFlag = false;
    }
    /**
     * 启用集中setState
     */
    useDoSetState(){
        this.useDoSetStateFlag = true;
    }
    /**
     * setState    启用集中setState场景则集中setState，否则统一setState
     * @param {*} state 
     */
    setState(state){
        if(this.useDoSetStateFlag){
            this.stateH = {...this.stateH, ...state};
        }else{
            this.page.setState(state);
        }
    }
    /**
     * 集中setState  启用集中setState时才生效
     */
    doSetState(){
        if(this.useDoSetStateFlag){
            this.page.setState(JSON.parse(JSON.stringify(this.stateH)), ()=>{
                this.stateH = {};
                this.useDoSetStateFlag = false;
            });    
        }
    }
}